// index.js
Page({
    
    srfc:function(){
        wx.navigateTo({
          url: '/pages/video/video',
        });
    },

    djgq: function (e) {
        let index = e.currentTarget.dataset.index;
        let itemData = this.data.array[index];
        // this.music=itemData.music
        
        if(this.loop == 1){
            this.tzbf()
        }

        this.music = itemData.music
        this.onLoad()
        this.loop = 1
        this.setData({
            fm: itemData.image,
            gm: itemData.name,
            ksbf:'/pages/images/02stop.png',
            
        });
    },
    // 暂停
    stopbf:function(){

        if(this.loop == 0){
            this.jxbf()
        }
        
        this.audioCtx.pause()
        this.setData({
            ksbf:'/pages/images/02.png'    
        })
        this.loop = 0
        this.cjbf()
    },

    tzbf:function(){
        this.audioCtx.stop()
    },


    // 播放
    jxbf:function(){
        this.audioCtx.play()
        console.log(this.music);
        console.log("继续播放");
    },

    // 创建
    cjbf:function(){
        this.audioCtx = wx.createInnerAudioContext()
        this.audioCtx.src = this.music
        this.audioCtx.volume = 0.5
        this.audioCtx.loop = false
    },

    // 播放
    onLoad: function () {
        this.cjbf()
        this.jxbf()
      },

    data:{
        array:[
        {name:1,image:'/pages/images/tu1.jpg',music:'/pages/music/1.mp3'},
        {name:2,image:'/pages/images/tu2.jpg',music:'/pages/music/2.mp3'},
        {name:3,image:'/pages/images/tu3.jpg',music:'/pages/music/3.mp3'},
        {name:4,image:'/pages/images/tu4.jpg',music:'/pages/music/4.mp3'},
        {name:5,image:'/pages/images/tu5.jpg',music:'/pages/music/1.mp3'},
        {name:6,image:'/pages/images/test.jpg',music:'/pages/music/2.mp3'},
    ],

    ksbf:'/pages/images/02.png',
    loop:0,
    music:''
    }
})


